package com.drx.service.service;

import com.drx.dao.TabAdministorMapper;
import com.drx.dao.TabUserMapper;
import com.drx.dojo.TabAdministor;
import com.drx.dojo.TabUser;
import com.drx.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class LoginServiceImpl implements LoginService {
    @Autowired
    TabUserMapper tabUserMapper;
    @Autowired
    TabAdministorMapper administorMapper;

    @Override
    public Map<String ,String > verifyStudent(Integer studentNum, String password) {
        //返回一个Map集合，里面包含如下几个值：loginResult登录结果，errorReason错误原因
        Map<String ,String > result=new HashMap<String, String>();
        TabUser tabUser = tabUserMapper.selectUserByStudentNum(studentNum);
        //判断用户是否存在
        if (tabUser==null){
            result.put("loginResult","false");
            result.put("errorReason","用户不存在");
        }else{
            //用户存在的情况下，判断密码是否输入正确
            if (password.equals(tabUser.getPassword())){
                //密码正确
                result.put("loginResult","true");
            }else{
                //密码错误
                result.put("loginResult","false");
                result.put("errorReason","密码输入错误");
            }
        }
        return result;
    }

    @Override
    public Map<String ,String > verifyAdministor(String  administorNum, String password) {
        //返回一个Map集合，里面包含如下几个值：loginResult登录结果，errorReason错误原因
        Map<String ,String > result=new HashMap<String, String>();
        TabAdministor tabUser = administorMapper.selectByPrimaryKey(administorNum);
        //判断用户是否存在
        if (tabUser==null){
            result.put("loginResult","false");
            result.put("errorReason","用户不存在");
        }else{
            //用户存在的情况下，判断密码是否输入正确
            if (password.equals(tabUser.getPassword())){
                //密码正确
                result.put("loginResult","true");
            }else{
                //密码错误
                result.put("loginResult","false");
                result.put("errorReason","密码输入错误");
            }
        }
        return result;
    }
}
